<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>招标项目管理</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %> 
    <!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <!-- 操作列更多弹窗 -->
    <div class="box box-primary" id="more" style="width:100px;height:35px;background-color:#2C3B41;position:absolute;z-index:9999;left:850px;top:100px;display:none;font-size:12px;border-top-color:#2C3B41;">
            <div class="box-body home-message" id="moreOp">
            </div>
    </div>

    <section class="content-header">
        <h1>招标项目管理</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">药品招标管理</a></li>
            <li class="active"><a href="#">采购项目管理</a></li>
            <li class="active"><a href="#">招标项目管理</a></li>
        </ol>
    </section>
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class=" form-inline">
                     <div class="form-group form-group-xs">
                        <label>项目名称：</label>
                        <select class="form-control" style="width:220px;" id="projId" name="projId"></select>
                    </div>
                     
                    <button type="button" onclick="gridSerch();" class="btn btn-success btn-sm"> 查&nbsp;询</button>
                </div>
            </div>
        </div>
        <table class="jqgrid" id="gridlist"></table>
   <div class=" box box-warning bottongroup"></div>
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp" %> 
    <script type="text/javascript">
        
        $(function () {
            $("#gridlist").jqGrid({
                url: "${ctx}/psProject/getProjectList.html",
                mtype: "POST",
                datatype: "json",
                autowidth: true,
                shrinkToFit: false,
                height: 270,
                colNames: [ '操作','projId','项目名称','采购开始日期', '采购结束日期', '状态'],
                colModel: [
                    { name: 'operate', width: "100px", align:"center",sortable: false, 
                        formatter : function(val, opts, rowdata) {
                        	if (rowdata.enroll == 0) {
                        		return "<a href='javascript:enroll(\""+rowdata.projId+"\",\""+rowdata.endtime+"\");' >报名</a>";
                        	}
                        	return "";
                        }
                    },
                    { name: 'projId', width: "0px" ,hidden:true, align:"center",sortable: false},
                    { name: 'name', width: "490px" , align:"left",sortable: false},
                    { name: 'starttime', width: "180px" , align:"center" ,sortable: false},
                    { name: 'endtime', width: "180px" , align:"center" ,sortable: false},
                    { name: 'status', width: "100px" , align:"center" ,sortable: false,formatter:function(val){return val==1?"启用":"停用";}}
                
                ],
                rowNum: 0,
                rownumbers: true,
                viewrecords: true,
                caption: "采购项目列表",
                jsonReader: {
                    repeatitems: false
                },
                loadComplete: function (data) { //完成服务器请求后，回调函数
                	 formatSelect("#projId",data.rows);
                	if(data.rows){
                		var projId =  data.conditions.defalutProjId;
       					if(projId!=null && projId!=""){
       	                	$("#projId").find("option").each(function(){
       	                			if($.trim($(this).val()) == $.trim(projId)){
       	                    			$(this).attr("selected",true).parents("#projId").attr("disabled","disabled");
       	                    			return;
       	                    		}
       	                	 }); 
                    		}
                	}else{
                		var projId =  data.conditions.defalutProjId;
       					if(projId!=null && projId!=""){
       	                	$("#projId").find("option").each(function(){
       	                			if($.trim($(this).val()) == $.trim(projId)){
       	                    			$(this).attr("selected",true).parents("#projId").attr("disabled","disabled");
       	                    			return;
       	                    		}
       	                	 }); 
                    		}else{
                    		  $.HN.message.alert("暂无招标目录数据", "消息", "info");
                    		}
                	}
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");  
            
        });
        

        //查询
        function gridSerch() {
            var projId = $("#projId").val();
            $("#gridlist").jqGrid('setGridParam',{  
                datatype:'json',
                postData:{"projId":projId}
            }).trigger("reloadGrid"); //重新载入  
        }
        
        
      //更多弹窗 包含 时间段查看、报价密码管理
        var flag = false;
        var mouseX=0;
        var mouseY=0;
        $(document).mousemove(function(e){
              mouseX=e.pageX;
              mouseY=e.pageY;
              var coord=$("#more").offset();
              if((mouseX<coord.left||mouseX>(coord.left+$("#more").width())||mouseY<coord.top||
                      mouseY>(coord.top+$("#more").height()))&&(mouseX<(coord.left+$("#more").width())||
                              mouseX>(coord.left+$("#more").width()+50)||mouseY<(coord.top+1)||mouseY>(coord.top+24+1))){
                  $("#more").hide();
              } 
        }); 
        function over(id,status,prodCompId){//鼠标移入
            $("#moreOp").children().remove();
            var coord=$("#"+id+"d").offset();
            $("#more").css("top",coord.top-1);
            $("#more").css("left",coord.left-$("#more").width());
            $("#more").show();
            $("#more").css("height",50);
            $("#more").css("padding-top",6);
            $("#moreOp").append("<a id='"+id+"w'  href='${ctx}/psProject/toPsProjectTimeView.html?projId="+id+"' style='color:#fff'>时间段查看</a>");
            $("#moreOp").append("<br/>")
            $("#moreOp").append("<a id='"+id+"x'  href='javascript:passwordManagement(\""+id+"\");' style='color:#fff'>报价密码管理</a>");
        }
     
        
        //报名
        function enroll(id,endTime) {
        if("${date}" <= endTime){
            $.HN.message.confirm("确定报名吗？", '', '').on(function (e) {
                if (e) {
            $.post("${ctx}/psProject/enroll.html", {
            	projId : id,
            }, function(result) {
                if (result.success) {
                    var curpage = $("#gridlist").jqGrid('getGridParam', 'page');
                    $.HN.message.alert("操作成功！", "消息", "success");
                } else {
                    $.HN.message.alert(result.msg || "操作失败！", "消息", "error");
                }
            }, "json")
                }
            });
        	}else{
       		 $.HN.message.alert("项目报名时间已结束！", "消息", "info");
       	}
        }
        
	   function passwordManagement(projId){
           $.HN.dialog.open({
            id:"passwordManagement",
            title:"招标项目报价密码管理",
            url:" ${ctx}/psProject/toPsPasswordSet.html?projId="+projId,
            data:{"interflowId":projId},
            width:"800px",
            height:"300px"
            }
            );
		}
	   
 
    </script>
</body>
</html>